﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AMS.DataAccess.Filter
{
    /// <summary>
    /// 提供对Int类型Bool类型字段的过滤器。
    /// </summary>
    public class IntegerFilterField : FilterField
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public IntegerFilterField(int value)
            :this(value, SqlOperations.Equals)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="operation"></param>
        public IntegerFilterField(int value, SqlOperations operation)
        {
            Value = value;
            Operation = operation;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="operation"></param>
        public IntegerFilterField(bool value, BooleanOperations operation)
        {
            Value = value ? 1 : 0;
            Operation = (SqlOperations)(int)operation;
        }

        /// <summary>
        /// 
        /// </summary>
        public int Value { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public SqlOperations Operation { get; private set; }

        /// <summary>
        /// 返回形如" = 123"的字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (Operation == SqlOperations.IsNotNull || Operation == SqlOperations.IsNull)
            {
                return SqlEnumUtils.NumberOperationsToString(Operation);
            }
            else
            {
                return SqlEnumUtils.NumberOperationsToString(Operation) + Value.ToString();
            }
        }
    }
}
